package com.medical.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.medical.system.common.Result;
import com.medical.system.model.Consultation;
import com.medical.system.service.ConsultationService;
import com.medical.system.vo.ConsultationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "问诊管理控制器")
@RequestMapping("/admin/system/consultation")
public class ConsultationController {

    @Autowired
    private ConsultationService consultationService;

    @ApiOperation("通过id查询数据")
    @GetMapping("/getConsultationById/{clientId}")
    public Result selectConsultationMenuByVo(@PathVariable Long clientId){
//        Consultation l = this.consultationService.findClientMenuByRoleId(clientId);
        Consultation l = this.consultationService.getById(clientId);
        return Result.ok(l);
    }
    @ApiOperation("查询及分页查询")
    @GetMapping("/{page}/{limit}")
    public Result selectConsultationPageByVo(@PathVariable Long page,
                                       @PathVariable Long limit,
                                       ConsultationVo consultationVo){
        IPage<Consultation> iPage = new Page<>(page,limit);

        iPage =   this.consultationService.selectPage(iPage,consultationVo);
        return Result.ok(iPage);
    }

    @ApiOperation("更新问诊信息")
    @PostMapping("/updateConsultation")
    public Result updateConsultation(@RequestBody Consultation consultation) {
        boolean isSuccess = this.consultationService.updateById(consultation);
        if (isSuccess) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation("添加问诊信息")
    @PostMapping("/addConsultation")
    public Result insertConsultation(@RequestBody Consultation consultation) {
        boolean saved = this.consultationService.save(consultation);
        if (saved) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation("删除问诊信息")
    @DeleteMapping("/removeConsultationById/{id}")
    public Result removeDepartment(@PathVariable Long id) {
        boolean removed = this.consultationService.removeById(id);
        if (removed) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

}
